package me.hl.time;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Created by Planck on 2016/2/23.
 */
public class DateDemo {

    private final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//时间转换

    public Calendar getCalendar() {
        return Calendar.getInstance();
    }

    @Test
    public void dateTest() {
        Calendar calendar = getCalendar();
        System.out.println(df.format(calendar.getTime()));
        calendar.set(Calendar.YEAR, 2); //改变时间
        System.out.println(df.format(calendar.getTime()));

        calendar.add(Calendar.DATE, -1);
        System.out.println(df.format(calendar.getTime()));
    }

}
